import java.util.Arrays;

public class Test {
        public static int missingNumber(int[] nums) {
            Arrays.sort(nums);
            for(int i = 0; i < nums.length-1; i++) {
                if (nums[i + 1] - nums[i] != 1) {
                    return (nums[i + 1] + nums[i]) / 2;
                }
            }
            if(nums[0] != 0){
                    return 0;
                }else return nums[nums.length-1] + 1;
        }
    public static void main(String[] args) {
        int[] nums = {0,1,3};
        int ret = missingNumber(nums);
        System.out.println(ret);
    }
}
